<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>我的优惠券-{{$SEO['title']}}</title>
    <meta name="keywords" content="{{$SEO['keywords']}}"/>
    <meta name="description" content="{{$SEO['description']}}"/>
    <!--公用css引用-->
    @include('front.common.style')
    <!--END/公用css引用-->
    <link rel="stylesheet" href="{{ asset("/dist/css/userCenter.css") }}">
</head>
<body>
@inject('request','Illuminate\Http\Request')

<!--公共头部-->
@include('front.common.header')
        <!--END/公共头部-->

<div class="inbox user-center">
    <div class="layout-margin unend">
        <div class="sidebar-end"></div>
        <div class="sidebar-start">
            @include('front.common.leftnav')
        </div>
@inject('pictureService','App\Interfaces\PictureService')
@inject('couponService','App\Interfaces\CouponService')


        <!--主体部分-->
        <div class="container">
            <div class="container-inner u-order">
                <div class="ui-brd-box1-">
                    <div class="tit-2 tit-skin-2">
                        <span class="h">优惠券</span>
                    </div>
                </div>

                <div class=" fn-mt10">

                    <div class="table-head fn-ohide">
                        <div class="order-type">
                            <ul class="link-list link-list-skin2">
                                <li @if(empty($search['type']) || $search['type']=='all') class="cur" @endif><a href="/my/coupon?type=all"> 所有优惠券<!-- （1） --></a></li>
                                <li @if(!empty($search['type']) && $search['type']==1) class="cur" @endif><a href="/my/coupon?type=1"> 全场通用券<!-- （3） --></a></li>
                                <li @if(!empty($search['type']) && $search['type']==2) class="cur" @endif><a href="/my/coupon?type=2"> 商品券<!-- （3） --></a></li>
                                <li @if(!empty($search['type']) && $search['type']==3) class="cur" @endif><a href="/my/coupon?type=3"> 分类券<!-- （1） --></a></li>
                                <li @if(!empty($search['type']) && $search['type']==4) class="cur" @endif><a href="/my/coupon?type=4"> 店铺券<!-- （1） --></a></li>
                                <li @if(!empty($search['type']) && $search['type']==5) class="cur" @endif><a href="/my/coupon?type=5"> 品牌券<!-- （1） --></a></li>
                            </ul>
                        </div>
                    </div>

                    <div id="coupon-list" class="coupon-list fn-cf">
                        <div class="coupon-box ui-cols-3 fn-fl">
                        <?php $current_time = date('Y-m-d H:i:s'); ?>
                        @foreach($user_coupon as $item)

                            <!-- <div class="coupon col @if($current_time>$item->end_time)coupon-outTime @endif"> -->
                            <div class="coupon col 
                                @if ($item->user_coupon_use_time || $current_time>$item->end_time)coupon-outTime @endif">
                                <div class="coupon-upper">
                                    <p>
                                        <a class="price-symbol">¥</a>
                                        <a class="amount">{{$item->value}}</a>
                                        <a class="scope">
                                        <?php

                                            if ($item->user_coupon_use_time) {
                                                echo '已使用';
                                            }elseif ($current_time>$item->end_time) {
                                                echo '已过期';
                                            }else{

                                                switch ($item->type) {
                                                    case '1':
                                                        echo '全场通用';
                                                        break;
                                                    case '2':
                                                        echo '商品使用';
                                                        break;
                                                    case '3':
                                                        echo '分类使用';
                                                        break;
                                                    case '4':
                                                        echo '店铺使用';
                                                        break;
                                                    case '5':
                                                        echo '品牌使用';
                                                        break;
                                                }
                                            }//end if()
                                        ?>
                                        </a>

                                    </p>
                                    <p class="fn-mt10">
                                        <a class="params">使用条件:</a>
                                        <a class="params-val">满{{$item->limit_fir}}元使用</a>
                                    </p>
                                    <p>
                                        <a class="params">有效时间:</a>
                                        <a class="params-val"><?php $date = date_create($item->start_time);echo date_format($date, 'Y-m-d'); ?>&nbsp;至&nbsp;<?php $date = date_create($item->end_time);echo date_format($date, 'Y-m-d'); ?></a>
                                    </p>
                                </div>
                                <div class="coupon-md"></div>

                                <div class="coupon-box-bottom">
                                    <a class="trash J_Delete" data-id="{{$item->user_coupon_id}}" title="删除优惠券">删除优惠券</a>
                                </div>
                            </div>
                            @endforeach

                        </div>
                    </div>

                    <!--分页-->

                    <!--  fn-tl/fn-tc/fn-tr 左中右定位; pager-big 大尺寸分页 可不加-->
                    <div class="js-pager pager fn-tr">
                        <ul class="pagination">
                        {!! $user_coupon->appends($search)->render() !!}
                        </ul>
                    </div>
                    <!--END/分页-->

                </div>



            </div>

        </div>
        <!--END/主体部分-->

    </div>
</div>



<!--公共尾部-->
@include('front.common.footer')

        <!--END/公共尾部-->

<!--公用js引用-->
@include('front.common.script')

        <!--END/公用js引用-->
<script>
    //删除优惠券
    $('.J_Delete').click(function(){
        var that=$(this),id=that.data('id');
        var box=that.closest('.coupon');
        layer.confirm('确定要删除吗？',function(index){

            //todo ajax 删除优惠券

            urls = "/my/coupon/"+id;
            $.ajax({
                type: "DELETE",
                url: urls,
                data: '',
                dataType: "json",
                headers: {
                    'X-CSRF-Token': "{{csrf_token()}}"
                },
                async:true,
                cache:false,
                success: function (msg) {

                    if(msg.status){
                        //删除成功
                    }//end if()

                }
            }); //end ajax


            box.slideUp(function(){
                box.remove();
            });
            layer.close(index);
        });
    });
</script>
</body>
</html>